package com.zretc.kscxmz.services.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zretc.kscxmz.entity.Account;
import com.zretc.kscxmz.mappers.AccountMapper;
import com.zretc.kscxmz.services.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class AccountServiceImpl implements AccountService {

    @Autowired
    private AccountMapper accountMapper;

    @Override
    public Map<String, String> login(String accountName, String password) {

        return accountMapper.findAccountByNameAndPwd(accountName,password);
    }

    @Override
    public PageInfo<Account> getAccountByPage(Map<String, String> param) {
        int pageNum =  Integer.parseInt(param.get("pageNum"));
        int pageSize =  Integer.parseInt(param.get("pageSize"));

        PageHelper.startPage(pageNum,pageSize);

        List<Account> list = accountMapper.findaccountInfo(param);

        PageInfo<Account> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }


    @Override
    public int addAccountInfo(Map<String, Object> param) {

        return accountMapper.insertaccountInfo(param);
    }

    @Override
    public int updateAccountInfo(Map<String, Object> param) {

        return accountMapper.updateaccountInfo(param);
    }

    @Override
    public int deleteAccountInfo(int accountId) {
        return accountMapper.modifyaccountInfoByaccountId(accountId);
    }

    @Override
    public Account getAccountInfoById(int accountId) {
        return accountMapper.findaccountInfoById(accountId);
    }

    @Override
    public Integer getRoleIdByName(String roleName) {
        return accountMapper.findRoleIdByName(roleName);
    }

    @Override
    public Integer getDeptIdByName(String deptName) {
        return accountMapper.findDeptIdByName(deptName);
    }

    @Override
    public Account toMakeSure(Map<String, Object> param) {
        return accountMapper.makeSure(param);
    }

    @Override
    public int motifyPwdByid(Map<String, Object> param) {
        return accountMapper.updatePwdByid(param);
    }

    @Override
    public int motifyInfoByid(Map<String, Object> param) {
        return accountMapper.updateInfoid(param);
    }

    @Override
    public Account getInfoById(int accountId) {
        return accountMapper.findInfoById(accountId);
    }
}
